package com.guaika.reggie.controller;

import ch.qos.logback.core.util.ContextUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaika.reggie.common.BaseContext;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.entity.ShoppingCart;
import com.guaika.reggie.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GuaiKa
 */
@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public ResultMessage<ShoppingCart> save(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.shoppingSave(shoppingCart);
    }


    /***
     * 查询购物车
     * @return
     */
    @GetMapping("/list")
    public ResultMessage<List<ShoppingCart>> list(){
        return shoppingCartService.shoppingList();
    }


    /**
     * 删减购物车菜品或套餐份数
     * @param shoppingCart
     * @return
     */
    @PostMapping("/sub")
    public ResultMessage<ShoppingCart> sub(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.shoppingSub(shoppingCart);
    }


    /***
     *清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public ResultMessage<String> clean(){
        return shoppingCartService.shoppingClean();
    }

}
